package com.personal.website.lottery.web.mail;

import java.util.Random;

/**
 * Created by Gavin on 2016/5/7.
 */
public class VerifyCodeSender {
    public static final SimpleMailSender sender = new SimpleMailSender();
    public static final String subject = "彩票网站验证码";

    public static String sendVerifyCode(String email) {
        String verifyCode = genVerifyCode();
        sender.sendTextMail(email,subject,verifyCode);
        return verifyCode;
    }

    private static String genVerifyCode() {
        String digit = "0,1,2,3,4,5,6,7,8,9";
        String bigLetter = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
        String smallLetter = bigLetter.toLowerCase();
        String[] arr = (digit + "," + bigLetter + "," + smallLetter).split(",");
        Random random = new Random();

        String verifyCode = "";
        for (int i = 0; i < 6; i ++){
            verifyCode += arr[random.nextInt(arr.length)];
        }
        return verifyCode;
    }
}
